<?php
define('SWOOLE_PATH',dirname(__FILE__));
require SWOOLE_PATH.'/Core/Base.php';
require SWOOLE_PATH.'/Core/Loader.php';
function &getConfig() {
    $locconfig = [];
    if(file_exists(SWOOLE_PATH.'/config/config.local.php')) {
        $locconfig = require SWOOLE_PATH . '/config/config.local.php';
    }
    $config = array_replace_recursive(require SWOOLE_PATH . '/config/config.php',$locconfig);
    unset($locconfig);
    return $config;
}
$config = getConfig();
spl_autoload_register(array(\Core\Loader::Instance($config['app']['loader']),'loadClass'));
\Core\Server::Instance()->serverConfig = $config['server'];
\Core\Server::Instance()->appConfig = $config['app'];
\Core\Server::Instance()->swooleConfig = $config['swoole'];
unset($config);
if(!isset($_SERVER['argv'][1])) {
    \Core\Server::Instance()->start();
    return;
}
switch ($_SERVER['argv'][1]) {
    case 'stop':
        \Core\Server::Instance()->stop();
        break;
    case 'reload':
        \Core\Server::Instance()->reloadWorker();
        break;
    case 'restart':
        \Core\Server::Instance()->stop();
        sleep(1);
        \Core\Server::Instance()->start();
        break;
    case 'start':
        \Core\Server::Instance()->start();
        break;
    default:
        echo "what do you want to do?\r\n";
}